package com.xjc.log;


import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author:谢君臣
 * @Date:2021/6/4-20:36
 * @version:1.0
 * @function:
 */

@Component
public class MyLog implements MethodBeforeAdvice, AfterReturningAdvice {
    /**
     * @param method method being invoked
     * @param objects arguments to the method
     * @param o target of the method invocation. May be {@code null}.
     * @throws Throwable
     */
    @Override
    public void before(Method method, Object[] objects, Object o) throws Throwable {
        System.out.println(o.getClass().getName() + "执行了方法：" + method.getName());
    }

    /**
     * @param returnValue the value returned by the method, if any
     * @param method method being invoked
     * @param objects arguments to the method
     * @param o1 target of the method invocation. May be {@code null}.
     * @throws Throwable if this object wishes to abort the call.
     */
    @Override
    public void afterReturning(Object returnValue, Method method, Object[] objects, Object o1) throws Throwable {
        System.out.println(o1.getClass().getName() + "执行了方法：" + method.getName()+",返回结果为："+returnValue.toString());
    }

}
